package com.li.singlepattern;

/**
 * 懒汉式2-懒汉式1的优化
 * 加入synchronized同步锁
 *
 * @author lirenchun
 */
public class RoleModel2 {
    /**
     * 私有化构造器
     */
    private RoleModel2() {
    }

    private static RoleModel2 roleModel2 = null;


    public static RoleModel2 getInstance() {
        if (roleModel2 == null) {
            synchronized (RoleModel2.class) {
                //二次验证，避免线程获取到对象锁后重复创造实例-确保实例唯一性
                if (roleModel2 == null) {
                     roleModel2=new RoleModel2();
                }
            }
        }
        return roleModel2;
    }

}
